package kr.hkit.androidcomplete02.ch01;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListFromArray extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.adapter_view);

		final ArrayAdapter<CharSequence> adapter = ArrayAdapter
				.createFromResource(this, R.array.county,
						android.R.layout.simple_expandable_list_item_1);

		ListView list = (ListView) findViewById(R.id.list_new);
		list.setAdapter(adapter);

		list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Log.d("ListViewTesource", "postion : " + position + ", id : "+id);
				String text = "Select Item=" + adapter.getItem(position);
				Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG)
						.show();
			}

		});
	}
}
